const mysql = require('mysql')
const {MYSQL_CONFIG} = require('../config/db.js')

//创建链接对象
const connection = mysql.createConnection(MYSQL_CONFIG)
//开始链接
connection.connect()

//统一执行sql函数
function exec(sql) {
  const promise = new Promise((resolve, reject) => {
    connection.query(sql,(err,result)=>{
      if (err){
        console.error(err)
        return
      }
      resolve(result)
    })
  })
  return promise
}

module.exports={
  exec,
  escape:mysql.escape
}